package net.bac.sbe.critical.item.info.dev.utils.xml.items;

import net.bac.sbe.web.sonar.server.dev.utils.xml.XmlBinding;

public class CriticalItemsConfiguration {

	private static CriticalItemsConfiguration instance = new CriticalItemsConfiguration();
	private CriticalItemsConfig criticalItems = null;

	public static CriticalItemsConfiguration getInstance() {
		if (null == instance.criticalItems) {
			init();
		}
		return instance;
	}

	private static void init() {
		instance.criticalItems = XmlBinding
				.getInstance()
				.xmlResourceToObject(
						CriticalItemsConfiguration.class
								.getResourceAsStream("/net/bac/sbe/web/items/critical/config/critical-items-config.xml"),
								CriticalItemsConfig.class);
	}


	public boolean isCriticalItem(String item){
		if (null != item){
			for (CriticalItemType criticalItem : criticalItems.getCriticalItem()) {
				if (item.matches(criticalItem.getRegularExpression())){
					return true;
				}
			}
		}
		return false;
	}

}
